package com.mebius.common.service;

import java.math.BigInteger;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;

import com.mebius.common.repository.IHibernateDao;

public abstract class BaseTreeService<T> {
	
	@Autowired
	protected IHibernateDao<T> hibernate ;
	
	@Autowired
	protected JdbcTemplate jdbcTemplate ;
	
	public int nextWeight(Long id) {
		String sql = "select case when max(weight) is null then 1 else (max(weight) + 1) end weight from sys_resource where parentId=?";
		BigInteger weight = (BigInteger) this.hibernate.queryObjectColSQL(sql, new Object[] { id });
		return weight.intValue();
	}
	
}
